﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using D2DEngine.Physics;
using D2DEngine.Components;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Collision.Shapes;
using FarseerPhysics.Factories;

namespace D2DEngine
{
    public class D2DActor : D2DSceneObject
    {
        protected Body body;

        /// <summary>
        /// The physical body of the actor
        /// </summary>
        public Body Body
        {
            get { return this.body; }
            set { this.body = value; }
        }

        /// <summary>
        /// The position of the actor
        /// </summary>
        ///         
        public override Vector2 Position
        {
            get { return this.body.Position; }
            set { this.body.Position = value; }
        }

        /// <summary>
        /// The Rotation of the actor
        /// </summary>
        ///         
        public override float Rotation
        {
            get { return this.body.Rotation; }
            set { this.body.Rotation = value; }
        }        
        
        public D2DActor()
        {              
        }

        /// <summary>
        /// Initializes the actor
        /// </summary>
        public override void OnRegister()
        {
            this.body.Enabled = true;
            this.body.UserData = this;

            base.OnRegister();
        }

        /// <summary>
        /// Copies the actor
        /// </summary>
        /// <param name="obj"></param>
        protected override void CopyTo(D2DObject obj)
        {            
            D2DActor actor = (D2DActor)obj;

            actor.Body = this.body.DeepClone();
            actor.Body.Enabled = false;
            
            base.CopyTo(obj);           
        }

        /// <summary>
        /// Disposes the actor
        /// </summary>
        public override void Dispose()
        {
            this.body.Dispose();

            base.Dispose();
        }

    }
}
